/**
 * app 升级
 */
import Vue from 'vue'
const SUCCESS = 1000000
const API_ROOT = server.root + '/newmanage'

const appListResource = Vue.resource(API_ROOT + '/common/app/list')
const updateAppResource = Vue.resource(API_ROOT + '/common/app/update')

export const getAppList = ({ dispatch }, params) => {
  return appListResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}

export const updateApp = ({ dispatch }, params) => {
  return updateAppResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data)
    }
    return Promise.reject(res.data)
  })
}

// 查询引导栏
const guideQueryResource = Vue.resource(API_ROOT + '/common/app/beta/ad/list')
export const guideQuery = ({ dispatch }, params) => {
  return guideQueryResource.get(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}

const guideUpdateResource = Vue.resource(
  API_ROOT + '/common/app/beta/ad/update'
)
export const guideUpdate = ({ dispatch }, params) => {
  return guideUpdateResource.save(params).then(res => {
    if (+res.data.code === SUCCESS) {
      return Promise.resolve(res.data.data)
    }
    return Promise.reject(res.data)
  })
}
